package com.newtouch.avmarketing.api.service.impl;

import com.newtouch.avmarketing.api.entity.Signature;
import com.newtouch.avmarketing.api.repo.SignatureRepo;
import com.newtouch.avmarketing.api.service.SignatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SignatureServiceImpl implements SignatureService {

    @Autowired
    private SignatureRepo signatureRepo;

    @Override
    public void saveOrUpdateSignature(Signature signature) {
        Signature signature1 = signatureRepo.findByPolicyCodeAndPageName(signature.getPolicyCode(), signature.getPageName());
        if (null != signature1){
            signature1.setBaseUrl(signature.getBaseUrl());
            signatureRepo.saveAndFlush(signature1);
        }else {
            signatureRepo.save(signature);
        }
    }

    @Override
    public Signature findByPolicyCodeAndPageName(String policyCode, String pageName) {
        return signatureRepo.findByPolicyCodeAndPageName(policyCode,pageName);
    }
}
